#此代码旨在测试减少Pack_B带来的性能提升  
#拟测试规模：1*k*8n

.text
.align 2
.global gemm_mNK_1_asm
gemm_mNK_1_asm:
    addi sp, sp, -64
    sd s7, 56(sp)
    sd s6, 48(sp)
    sd s5, 40(sp)
    sd s4, 32(sp)
    sd s3, 24(sp)
    sd s2, 16(sp)
    sd s1,  8(sp)
    sd s0,  0(sp)

#gemm_mNK_1_asm(int _m, int _n, int _k, float alpha, float* _a, float* _b, float* _c, int ldc, float beta, int ldb);
#min_i:  m
#min_jj: n
#min_l:  k
#ldc :   m
################
#a0: _m
#a1: _n
#a2: _k
#fa0: alpha
#a3: &_a
#a4: &_b
#a5: &_c
#a6: ldc
#fa1: beta
#a7: ldb

    #vsetvli t0, zero, e32, m2, ta, ma
    fcvt.s.w ft11, x0             #初始化浮点寄存器ft11==0
    li t0, 4
    li s11, 8
    li s10, 1
    addi s9, a2, 0
    addi s8, a1, 0
    addi s7, a0, 0
    addi s5, a5, 0
    addi s4, a4, 0
    addi s3, a3, 0
    mul a6, a6, t0
    mul a7, a7, t0
    Jude_a1:
    blt a1, s11, _n_Less_8
        ###
        ###
        ###
        addi a1, a1, -8
        blt a0, s11, _m_Less_8
        _m_Less_8:
            andi t0, a0, 4
            beqz t0, _m_Not_inclu_4
            ###
            ###
            ###
            _m_Not_inclu_4:
                andi t1, a0, 2
                beqz t1, _m_Not_inclu_2
                ###
                ###
                ###
                _m_Not_inclu_2:
                    andi t1, a0, 1
                    beqz t1, END

                    fmv.s fs1, ft11
                    fmv.s fs2, ft11
                    fmv.s fs3, ft11
                    fmv.s fs4, ft11
                    fmv.s fs5, ft11
                    fmv.s fs6, ft11
                    fmv.s fs7, ft11
                    fmv.s fs8, ft11

                    add t0, a4, a7
                    add t1, t0, a7
                    add t2, t1, a7
                    add t3, t2, a7
                    add t4, t3, a7
                    add t5, t4, a7
                    add t6, t5, a7
                
                    flw fs0, (a3) 
                    flw ft0, (a4)
                    flw ft1, (t0)
                    flw ft2, (t1)
                    flw ft3, (t2)
                    flw ft4, (t3)
                    flw ft5, (t4)
                    flw ft6, (t5)
                    flw ft7, (t6)
                    
                    Jude_a2:
                    beqz a2, Save_c_m_1
                    addi a3, a3, 4
                    addi a4, a4, 4 
                    add t0, a4, a7
                    add t1, t0, a7
                    add t2, t1, a7
                    add t3, t2, a7
                    add t4, t3, a7
                    add t5, t4, a7
                    add t6, t5, a7

                    fmadd.s fs1, fs0, ft0, fs1
                    fmadd.s fs2, fs0, ft1, fs2
                    fmadd.s fs3, fs0, ft2, fs3
                    fmadd.s fs4, fs0, ft3, fs4
                    fmadd.s fs5, fs0, ft4, fs5
                    fmadd.s fs6, fs0, ft5, fs6
                    fmadd.s fs7, fs0, ft6, fs7
                    fmadd.s fs8, fs0, ft7, fs8

                    flw fs0, (a3)
                    flw ft0, (s4)
                    flw ft1, (t0)
                    flw ft2, (t1)
                    flw ft3, (t2)
                    flw ft4, (t3)
                    flw ft5, (t4)
                    flw ft6, (t5)
                    flw ft7, (t6)

                    addi a2, a2, -1
                    j Jude_a2

                    Save_c_m_1:
                        add t0, a5, a6
                        add t1, t0, a6
                        add t2, t1, a6
                        add t3, t2, a6
                        add t4, t3, a6
                        add t5, t4, a6
                        add t6, t5, a6

                        flw ft0, (a5)
                        flw ft1, (t0)
                        flw ft2, (t1)
                        flw ft3, (t2)
                        flw ft4, (t3)
                        flw ft5, (t4)
                        flw ft6, (t5)
                        flw ft7, (t6)

                        fmadd.s fs1, fs1, fa0, ft0
                        fmadd.s fs2, fs2, fa0, ft1
                        fmadd.s fs3, fs3, fa0, ft2
                        fmadd.s fs4, fs4, fa0, ft3
                        fmadd.s fs5, fs5, fa0, ft4
                        fmadd.s fs6, fs6, fa0, ft5
                        fmadd.s fs7, fs7, fa0, ft6
                        fmadd.s fs8, fs8, fa0, ft7

                        fsw fs1, (a5)
                        fsw fs2, (t0)
                        fsw fs3, (t1)
                        fsw fs4, (t2)
                        fsw fs5, (t3)
                        fsw fs6, (t4)
                        fsw fs7, (t5)
                        fsw fs8, (t6)

                        ###############################
                        ###Update para and address！###
                        ###############################
                        mv a2, s9

                        li t1, 8
                        mul t0, a6, t1
                        add a5, a5, t0

                        mv a3, s3

                        mv a4, s4
                        li t3, 8
                        mul t2, a7, t3  
                        add a4, a4, t2
                        j Jude_a1
                                
 
    _n_Less_8:
        andi t1, a0, 4
        beqz t1, _n_Not_inclu_4

    
    _n_Not_inclu_4:
        andi t1, a0, 2
        beqz t1, _n_Not_inclu_2
        
    _n_Not_inclu_2:
        

END:
  ld s7, 56(sp)
  ld s6, 48(sp)
  ld s5, 40(sp)
  ld s4, 32(sp)
  ld s3, 24(sp)
  ld s2, 16(sp)
  ld s1,  8(sp)
  ld s0,  0(sp)
  addi sp, sp, 64
ret





